#include <iostream>
using namespace std;
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 

int main()
{
	int y,d;
	cin>>y;
	cin>>d;
	if(y%400==0||(y%4==0&&y%100)){
		month[2]=29;
	}
	else{
		month[2]=28;
	}
	int n=1;
	while(d>month[n]){
		d=d-month[n];
		n++;
	}
	cout<<n<<endl<<d<<endl;
	return 0;
}
